$app_id		= "1483018411914605";
$app_secret	= "f391ea3f238e2055f3de725bcb03510d";
$site_url	= "Your Site URL goes here";

include_once "src/facebook.php";
 
$facebook = new Facebook(array(
	'appId'		=> $1483018411914605,
	'secret'	=> $f391ea3f238e2055f3de725bcb03510d,
	));
 
$user = $facebook->getUser();

if($user){
//==================== Single query method ======================================
	try{
		// Proceed knowing you have a logged in user who's authenticated.
		$user_profile = $facebook->api('/me');
	}catch(FacebookApiException $e){
		error_log($e);
		$user = NULL;
	}
//==================== Single query method ends =================================
}

//Application Configurations
$app_id        = "1483018411914605";
$app_secret    = "f391ea3f238e2055f3de725bcb03510d";
$site_url      = "Your Site URL goes here";
 
try{
    include_once "src/facebook.php";
}catch(Exception $e){
    error_log($e);
}
// Create our application instance
$facebook = new Facebook(array(
    'appId'     => $app_id,
    'secret'    => $app_secret,
    ));
 
// Get User ID
$user = $facebook->getUser();
 
if($user){
    try{
        // Proceed knowing you have a logged in user who's authenticated.
        $user_profile = $facebook->api('/me');
    }catch(FacebookApiException $e){
        error_log($e);
        $user = NULL;
    }
}

if($user){
    // Get logout URL
    $logoutUrl = $facebook->getLogoutUrl();
}else{
    // Get login URL
    $loginUrl = $facebook->getLoginUrl(array(
        'scope'            => 'publish_stream user_groups',
        'redirect_uri'     => $site_url,
        ));
}

$user_info         = $facebook->api('/'.$user);
$friends_list      = $facebook->api('/'.$user.'/friends');
$groups            = $facebook->api('/'.$user.'/groups');
$pages             = $facebook->api('/'.$user.'/likes');

$queries = array(
    array('method' => 'GET', 'relative_url' => '/'.$user),
    array('method' => 'GET', 'relative_url' => '/'.$user.'/friends'),
    array('method' => 'GET', 'relative_url' => '/'.$user.'/groups'),
    array('method' => 'GET', 'relative_url' => '/'.$user.'/likes'),
    );

try{
    $batchResponse = $facebook->api('?batch='.json_encode($queries), 'POST');
}catch(Exception $o){
    error_log($o);
}

$batchPost[] = array(
    'method' => 'POST',
    'relative_url' => "/{ID1}/feed",
    'body' => http_build_query($body) );
$batchPost[] = array(
    'method' => 'POST',
    'relative_url' => "/{ID2}/feed",
    'body' => http_build_query($body) );
$batchPost[] = array(
    'method' => 'POST',
    'relative_url' => "/{ID3}/feed",
    'body' => http_build_query($body) );
 
$multiPostResponse = $facebook->api('?batch='.urlencode(json_encode($batchPost)), 'POST');


if(isset($_POST['submit'])){
    $body = array(
        'message'        => $_POST['message'],
        'link'           => $_POST['link'],
        'picture'        => $_POST['picture'],
        'name'           => $_POST['name'],
        'caption'        => $_POST['caption'],
        'description'    => $_POST['description'],
        );
 
    $batchPost=array();
 
    $i=1;
    foreach($_POST as $key => $value) {
        if(strpos($key,"id_") === 0) {
            $batchPost[] = array(
                        'method' => 'POST',
                        'relative_url' => "/$value/feed",
                        'body' => http_build_query($body)
                        );
            if($i++ == 50) {
                try{
                    $multiPostResponse = $facebook->api(
                        '?batch='.urlencode(json_encode($batchPost)),
                        'POST'
                        );
                }catch(FacebookApiException $e){
                    error_log($e);
                    echo("Batch Post Failed");
                }
                unset($batchPost);
                $i=1;
            }
        }
    }
    if(isset($batchPost) && count($batchPost) > 0 ) {
        try{
            $multiPostResponse = $facebook->api('?batch='.urlencode(json_encode($batchPost)), 'POST');
        }catch(FacebookApiException $e){
            error_log($e);
            echo("Batch Post Failed");
        }
    }
}